<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="theme-color" content="#0078E7"><meta name="author" content="爱肖彤真是太好了"><meta name="copyright" content="爱肖彤真是太好了"><meta name="generator" content="Hexo 5.1.1"><meta name="theme" content="hexo-theme-yun"><title>linux学习 | 工藤旧二の博客</title><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@900&amp;display=swap" media="none" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/star-markdown-css@0.1.19/dist/yun/yun-markdown.min.css"><script src="//at.alicdn.com/t/font_1140697_stqaphw3j4.js" async></script><script src="https://cdn.jsdelivr.net/npm/scrollreveal/dist/scrollreveal.min.js" defer></script><script>document.addEventListener("DOMContentLoaded", () => {
  [".post-card",".post-content img"].forEach((target)=> {
    ScrollReveal().reveal(target);
  })
});
</script><link rel="shortcut icon" type="image/svg+xml" href="/task/yun.ico"><link rel="mask-icon" href="/task/yun.ico" color="#0078E7"><link rel="alternate icon" href="/yun.ico"><link rel="preload" href="/task/css/hexo-theme-yun.css" as="style"><link rel="preload" href="/task/js/utils.js" as="script"><link rel="preload" href="/task/js/hexo-theme-yun.js" as="script"><link rel="prefetch" href="/task/js/sidebar.js" as="script"><link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin><link rel="stylesheet" href="/task/css/hexo-theme-yun.css"><link rel="alternate" href="/task/atom.xml" title="工藤旧二の博客" type="application/atom+xml"><script id="yun-config">
    const Yun = window.Yun || {};
    window.CONFIG = {"root":"/task/","title":"工藤旧二の博客","version":"0.9.7","anonymous_image":"https://cdn.jsdelivr.net/gh/YunYouJun/cdn/img/avatar/none.jpg","say":{"api":"https://v1.hitokoto.cn","hitokoto":true},"local_search":{"path":"/task/search.xml"},"fireworks":{"colors":["102, 167, 221","62, 131, 225","33, 78, 194"]}};
  </script><script>(function(){
  var bp = document.createElement('script');
  var curProtocol = window.location.protocol.split(':')[0];
  if (curProtocol === 'https') {
    bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
  }
  else {
    bp.src = 'http://push.zhanzhang.baidu.com/push.js';
  }
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(bp, s);
})();</script><meta name="description" content="linux学习[TOC] 一、虚拟软件安装1 虚拟化技术kvm，vmware，这两个的功能是可以在硬件上开辟一个虚拟空间，在这个空间上可以安装不同的操作系统  iaas 基础设置及服务 paas 平台及服务  saas 软件及服务  openstack管理在硬件上安装的所有的操作系统，实现iaas docker：实现paas k8s：容器编排，管理不同机器上的容器（docker容器） 2 cent">
<meta property="og:type" content="article">
<meta property="og:title" content="linux学习">
<meta property="og:url" content="http://huang_zhao.gitee.io/task/2021/03/15/%E5%85%B6%E4%BB%96/linux%E5%AD%A6%E4%B9%A0/index.html">
<meta property="og:site_name" content="工藤旧二の博客">
<meta property="og:description" content="linux学习[TOC] 一、虚拟软件安装1 虚拟化技术kvm，vmware，这两个的功能是可以在硬件上开辟一个虚拟空间，在这个空间上可以安装不同的操作系统  iaas 基础设置及服务 paas 平台及服务  saas 软件及服务  openstack管理在硬件上安装的所有的操作系统，实现iaas docker：实现paas k8s：容器编排，管理不同机器上的容器（docker容器） 2 cent">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-03-15T05:33:43.000Z">
<meta property="article:modified_time" content="2021-06-27T09:25:19.000Z">
<meta property="article:author" content="爱肖彤真是太好了">
<meta property="article:tag" content="操作系统">
<meta name="twitter:card" content="summary"><script src="/task/js/ui/mode.js"></script><link rel="stylesheet" href="/task/css/prism.css" type="text/css"></head><body><script defer src="https://cdn.jsdelivr.net/npm/animejs@latest/anime.min.js"></script><script defer src="/task/js/ui/fireworks.js"></script><canvas class="fireworks"></canvas><div class="container"><a class="sidebar-toggle hty-icon-button" id="menu-btn"><div class="hamburger hamburger--spin" type="button"><span class="hamburger-box"><span class="hamburger-inner"></span></span></div></a><div class="sidebar-toggle sidebar-overlay"></div><aside class="sidebar"><script src="/task/js/sidebar.js"></script><ul class="sidebar-nav"><li class="sidebar-nav-item sidebar-nav-toc hty-icon-button sidebar-nav-active" data-target="post-toc-wrap" title="文章目录"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-list-ordered"></use></svg></li><li class="sidebar-nav-item sidebar-nav-overview hty-icon-button" data-target="site-overview-wrap" title="站点概览"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-passport-line"></use></svg></li></ul><div class="sidebar-panel" id="site-overview-wrap"><div class="site-info fix-top"><a class="site-author-avatar" href="/task/about/" title="爱肖彤真是太好了"><img width="96" loading="lazy" src="/task/Yun.png" alt="爱肖彤真是太好了"></a><div class="site-author-name"><a href="/task/about/">爱肖彤真是太好了</a></div><a class="site-name" href="/task/about/site.html">工藤旧二の博客</a><sub class="site-subtitle"></sub><div class="site-desciption"></div></div><nav class="site-state"><a class="site-state-item hty-icon-button icon-home" href="/task/" title="首页"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-home-4-line"></use></svg></span></a><div class="site-state-item"><a href="/task/archives/" title="归档"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-archive-line"></use></svg></span><span class="site-state-item-count">57</span></a></div><div class="site-state-item"><a href="/task/categories/" title="分类"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-folder-2-line"></use></svg></span><span class="site-state-item-count">2</span></a></div><div class="site-state-item"><a href="/task/tags/" title="标签"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-price-tag-3-line"></use></svg></span><span class="site-state-item-count">50</span></a></div><a class="site-state-item hty-icon-button" target="_blank" rel="noopener" href="https://yun.yunyoujun.cn" title="文档"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-settings-line"></use></svg></span></a></nav><hr style="margin-bottom:0.5rem"><div class="links-of-author"><a class="links-of-author-item hty-icon-button" rel="noopener" title="RSS" target="_blank" style="color:orange"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-rss-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="QQ" target="_blank" style="color:#12B7F5"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-qq-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="GitHub" target="_blank" style="color:#6e5494"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-github-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="微博" target="_blank" style="color:#E6162D"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-weibo-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="豆瓣" target="_blank" style="color:#007722"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-douban-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://music.163.com/#/user/home?id=552858287" title="网易云音乐" target="_blank" style="color:#C20C0C"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-netease-cloud-music-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="知乎" target="_blank" style="color:#0084FF"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-zhihu-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://space.bilibili.com/15081363" title="哔哩哔哩" target="_blank" style="color:#FF8EB3"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-bilibili-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="Twitter" target="_blank" style="color:#1da1f2"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-twitter-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="Telegram Channel" target="_blank" style="color:#0088CC"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-telegram-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="E-Mail" target="_blank" style="color:#8E71C1"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-mail-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="Travelling" target="_blank" style="color:var(--hty-text-color)"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-send-plane-2-line"></use></svg></a></div><hr style="margin:0.5rem 1rem"><div class="links"><a class="links-item hty-icon-button" href="/task/links/" title="我的小伙伴们" style="color:dodgerblue"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-genderless-line"></use></svg></a></div><br><a class="links-item hty-icon-button" id="toggle-mode-btn" href="javascript:;" title="Mode" style="color: #f1cb64"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-contrast-2-line"></use></svg></a></div><div class="sidebar-panel sidebar-panel-active" id="post-toc-wrap"><div class="post-toc"><div class="post-toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#linux%E5%AD%A6%E4%B9%A0"><span class="toc-text">linux学习</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E8%99%9A%E6%8B%9F%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85"><span class="toc-text">一、虚拟软件安装</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E8%99%9A%E6%8B%9F%E5%8C%96%E6%8A%80%E6%9C%AF"><span class="toc-text">1 虚拟化技术</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-centos-%E5%AE%89%E8%A3%85"><span class="toc-text">2 centos 安装</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81-bash-shell-%E4%BB%8B%E7%BB%8D%E5%92%8C%E4%BD%BF%E7%94%A8"><span class="toc-text">二、 bash shell 介绍和使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E4%BB%80%E4%B9%88%E6%98%AFBash-shell-%E5%A3%B3"><span class="toc-text">1 什么是Bash shell(壳)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E8%83%BD%E5%B9%B2%E4%BB%80%E4%B9%88"><span class="toc-text">2 能干什么</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E5%B9%B3%E6%97%B6%E6%88%91%E4%BB%AC%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8Shell%E5%91%A2%EF%BC%9F"><span class="toc-text">3 平时我们如何使用Shell呢？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-shell%E6%8F%90%E7%A4%BA%E7%AC%A6"><span class="toc-text">4  shell提示符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-Shell%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95"><span class="toc-text">5 Shell基础语法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-%E5%91%BD%E4%BB%A4%E8%A1%A5%E5%85%A8"><span class="toc-text">6 命令补全</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-%E5%91%BD%E4%BB%A4%E5%BF%AB%E6%8D%B7%E9%94%AE"><span class="toc-text">7 命令快捷键</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-history"><span class="toc-text">8 history</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-%E7%BD%91%E7%BB%9C%E9%97%AE%E9%A2%98"><span class="toc-text">9 网络问题</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89%E3%80%81linux%E5%9F%BA%E6%9C%AC%E5%91%BD%E4%BB%A4"><span class="toc-text">三、linux基本命令</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%91%BD%E4%BB%A4%E5%88%AB%E5%90%8D"><span class="toc-text">1 命令别名</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E2%80%93help%E5%B8%AE%E5%8A%A9"><span class="toc-text">2 –help帮助</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E7%9B%AE%E5%BD%95%E4%BB%8B%E7%BB%8D"><span class="toc-text">3 目录介绍</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E7%9B%AE%E5%BD%95%E4%B9%8Busr"><span class="toc-text">1 目录之usr</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E7%9B%AE%E5%BD%95%E4%B9%8Betc"><span class="toc-text">2 目录之etc</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E7%9B%AE%E5%BD%95%E4%B9%8Bvar-dev"><span class="toc-text">3 目录之var dev</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E7%9B%AE%E5%BD%95%E4%B9%8Bproc"><span class="toc-text">4 目录之proc</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E6%96%87%E4%BB%B6%E7%AE%A1%E7%90%86"><span class="toc-text">4 文件管理</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%88%9B%E5%BB%BA"><span class="toc-text">1 创建</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E6%9F%A5%E7%9C%8B"><span class="toc-text">2 查看</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E5%A4%8D%E5%88%B6"><span class="toc-text">3 复制</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E7%A7%BB%E5%8A%A8"><span class="toc-text">4 移动</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-%E5%88%A0%E9%99%A4"><span class="toc-text">5 删除</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6-%E6%9F%A5%E7%9C%8B%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9cat"><span class="toc-text">6 查看文件内容cat</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7-%E6%9F%A5%E7%9C%8B%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9less%EF%BC%8Cmore"><span class="toc-text">7 查看文件内容less，more</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-%E6%9F%A5%E7%9C%8B%E6%96%87%E4%BB%B6%E5%A4%B4head%EF%BC%8C%E5%B0%BEtail"><span class="toc-text">8 查看文件头head，尾tail</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9-%E8%BF%87%E6%BB%A4%E6%96%87%E4%BB%B6"><span class="toc-text">9 过滤文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#10-%E8%81%94%E7%BD%91%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6"><span class="toc-text">10 联网下载文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#11-%E6%9C%AC%E5%9C%B0%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD"><span class="toc-text">11 本地上传下载</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#12-%E6%96%87%E4%BB%B6%E6%9F%A5%E6%89%BE"><span class="toc-text">12 文件查找</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#13-%E5%91%BD%E4%BB%A4%E6%9F%A5%E6%89%BE"><span class="toc-text">13 命令查找</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#14-%E6%96%87%E4%BB%B6%E5%AD%97%E7%AC%A6%E5%A4%84%E7%90%86"><span class="toc-text">14 文件字符处理</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#15-%E7%B3%BB%E7%BB%9F%E6%96%87%E4%BB%B6%E5%B1%9E%E6%80%A7"><span class="toc-text">15 系统文件属性</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#16-%E7%B3%BB%E7%BB%9F%E9%93%BE%E6%8E%A5%E6%96%87%E4%BB%B6"><span class="toc-text">16 系统链接文件</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#16-1%E8%BD%AF%E8%BF%9E%E6%8E%A5"><span class="toc-text">16.1软连接</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#16-2-%E7%A1%AC%E9%93%BE%E6%8E%A5"><span class="toc-text">16.2 硬链接</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-%E8%AF%BB%E5%86%99%E6%96%87%E4%BB%B6"><span class="toc-text">5 读写文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-%E7%94%A8%E6%88%B7%E7%9B%B8%E5%85%B3"><span class="toc-text">6 用户相关</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E7%94%A8%E6%88%B7%E4%B8%8E%E6%9D%83%E9%99%90"><span class="toc-text">1 用户与权限</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90%EF%BC%88%E7%89%B9%E6%AE%8A%E6%9D%83%E9%99%90%EF%BC%89"><span class="toc-text">2 文件权限（特殊权限）</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-%E5%8E%8B%E7%BC%A9%E8%A7%A3%E5%8E%8B"><span class="toc-text">7 压缩解压</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-%E8%BD%AF%E4%BB%B6%E7%AE%A1%E7%90%86%EF%BC%9Arpm"><span class="toc-text">8 软件管理：rpm</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-yum%E4%BB%93%E5%BA%93%EF%BC%8C%E6%BA%90"><span class="toc-text">9 yum仓库，源</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#10-%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90chmod"><span class="toc-text">10 文件权限chmod</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#11-%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85%E8%BD%AF%E4%BB%B6"><span class="toc-text">11 源码安装软件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#12-%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86"><span class="toc-text">12 进程管理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#13-%E7%B3%BB%E7%BB%9F%E6%9C%8D%E5%8A%A1"><span class="toc-text">13 系统服务</span></a></li></ol></li></ol></li></ol></div></div></div></aside><main class="sidebar-translate" id="content"><div id="post"><article class="post-block" itemscope itemtype="https://schema.org/Article"><link itemprop="mainEntityOfPage" href="http://huang_zhao.gitee.io/task/task/2021/03/15/%E5%85%B6%E4%BB%96/linux%E5%AD%A6%E4%B9%A0/"><span hidden itemprop="author" itemscope itemtype="https://schema.org/Person"><meta itemprop="name" content="爱肖彤真是太好了"><meta itemprop="description"></span><span hidden itemprop="publisher" itemscope itemtype="https://schema.org/Organization"><meta itemprop="name" content="工藤旧二の博客"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">linux学习</h1><div class="post-meta"><div class="post-time" style="display:block"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-calendar-line"></use></svg></span> <time title="创建时间：2021-03-15 13:33:43" itemprop="dateCreated datePublished" datetime="2021-03-15T13:33:43+08:00">2021-03-15</time><span class="post-meta-divider">-</span><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-calendar-2-line"></use></svg></span> <time title="修改时间：2021-06-27 17:25:19" itemprop="dateModified" datetime="2021-06-27T17:25:19+08:00">2021-06-27</time></div><span class="post-count"><span class="post-symbolcount"><span class="post-meta-item-icon" title="本文字数"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-file-word-line"></use></svg></span> <span title="本文字数">6.5k</span><span class="post-meta-divider">-</span><span class="post-meta-item-icon" title="阅读时长"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-timer-line"></use></svg></span> <span title="阅读时长">27m</span></span></span><span class="post-busuanzi"><span class="post-meta-divider">-</span><span class="post-meta-item-icon" title="阅读次数"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-eye-line"></use></svg> <span id="busuanzi_value_page_pv"></span></span></span><div class="post-classify"><span class="post-category"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-folder-line"></use></svg></span> <span itemprop="about" itemscope itemtype="https://schema.org/Thing"><a class="category" href="/task/categories/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/" style="--text-color:var(--hty-text-color)" itemprop="url" rel="index"><span itemprop="text">技术分享</span></a></span></span><span class="post-tag"><span class="post-meta-divider">-</span><a class="tag" href="/task/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" style="--text-color:var(--hty-text-color)"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-price-tag-3-line"></use></svg></span><span class="tag-name">操作系统</span></a></span></div></div></header><section class="post-body" itemprop="articleBody"><div class="post-content markdown-body" style="--smc-primary:#0078E7;"><h1 id="linux学习"><a href="#linux学习" class="headerlink" title="linux学习"></a>linux学习</h1><p>[TOC]</p>
<h2 id="一、虚拟软件安装"><a href="#一、虚拟软件安装" class="headerlink" title="一、虚拟软件安装"></a>一、虚拟软件安装</h2><h3 id="1-虚拟化技术"><a href="#1-虚拟化技术" class="headerlink" title="1 虚拟化技术"></a>1 虚拟化技术</h3><p>kvm，vmware，这两个的功能是可以在硬件上开辟一个虚拟空间，在这个空间上可以安装不同的操作系统</p>
<ul>
<li>iaas 基础设置及服务</li>
<li>paas 平台及服务 </li>
<li>saas 软件及服务</li>
</ul>
<p>openstack管理在硬件上安装的所有的操作系统，实现iaas</p>
<p>docker：实现paas</p>
<p>k8s：容器编排，管理不同机器上的容器（docker容器）</p>
<h3 id="2-centos-安装"><a href="#2-centos-安装" class="headerlink" title="2 centos 安装"></a>2 centos 安装</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># DHCP :</span>
DHCP（动态主机配置协议）是一个局域网的网络协议。指的是由服务器控制一段IP地址范围，客户机登录服务器时就可以自动获得服务器分配的IP地址和子网掩码。默认情况下，DHCP作为Windows Server的一个服务组件不会被系统自动安装，还需要管理员手动安装并进行必要的配置
<span class="token comment" spellcheck="true"># dns:可以把域名地址转换成ip地址</span>
<span class="token comment" spellcheck="true"># 主机名：生产环境，要有意义  地址+楼层+房间号+业务</span>
<span class="token comment" spellcheck="true"># swap分区：交换分区</span>
<span class="token comment" spellcheck="true"># 关于分区</span>
linux 分区结构为树结构， windows 为森林结构，所以有C盘D盘之类的， 而linux <span class="token operator">/</span>分区就是根分区， swap可以理解为虚拟内存， <span class="token operator">/</span>boot 这是个目录， 可以分成一个分区，然后挂载到<span class="token operator">/</span>boot目录， 也可以只用一个<span class="token operator">/</span>分区， 里面会有boot目录的，保存的是引导文件，内核等等的东东</code></pre>
<h2 id="二、-bash-shell-介绍和使用"><a href="#二、-bash-shell-介绍和使用" class="headerlink" title="二、 bash shell 介绍和使用"></a>二、 bash shell 介绍和使用</h2><h3 id="1-什么是Bash-shell-壳"><a href="#1-什么是Bash-shell-壳" class="headerlink" title="1 什么是Bash shell(壳)"></a>1 什么是Bash shell(壳)</h3><pre class=" language-python"><code class="language-python">是一个命令解释器，就是一个软件  执行就是bash，可以在里面输入命令，做交互，exit退出</code></pre>
<h3 id="2-能干什么"><a href="#2-能干什么" class="headerlink" title="2 能干什么"></a>2 能干什么</h3><pre class=" language-python"><code class="language-python">原来在windows上点点点完成的是，它都能做到

使用Shell实现对Linux系统的大部分管理，例如<span class="token punctuation">:</span>
<span class="token number">1</span><span class="token punctuation">.</span>文件管理<span class="token punctuation">(</span>文件创建，移动，复制，删除，编辑…<span class="token punctuation">)</span>
<span class="token number">2</span><span class="token punctuation">.</span>权限管理<span class="token punctuation">(</span>不同用户不通权限<span class="token punctuation">)</span>
<span class="token number">3</span><span class="token punctuation">.</span>用户管理（创建，删除…<span class="token punctuation">.</span>）
<span class="token number">4</span><span class="token punctuation">.</span>磁盘管理（挂载）
<span class="token number">5</span><span class="token punctuation">.</span>网络管理
<span class="token number">6</span><span class="token punctuation">.</span>软件管理
等等</code></pre>
<h3 id="3-平时我们如何使用Shell呢？"><a href="#3-平时我们如何使用Shell呢？" class="headerlink" title="3 平时我们如何使用Shell呢？"></a>3 平时我们如何使用Shell呢？</h3><pre class=" language-python"><code class="language-python"><span class="token number">1</span> 输入命令，低效
<span class="token number">2</span> shell script：shell脚本  ，批量执行命令</code></pre>
<h3 id="4-shell提示符"><a href="#4-shell提示符" class="headerlink" title="4  shell提示符"></a>4  shell提示符</h3><pre class=" language-python"><code class="language-python"><span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># root：当前用户</span>
<span class="token comment" spellcheck="true"># @ ：没有意义</span>
<span class="token comment" spellcheck="true">#lqz：主机名</span>
<span class="token comment" spellcheck="true"># ~：家目录</span>
<span class="token comment" spellcheck="true"># #:表示超级用户</span>
<span class="token punctuation">[</span>lqz@lqz <span class="token operator">~</span><span class="token punctuation">]</span>$ </code></pre>
<h3 id="5-Shell基础语法"><a href="#5-Shell基础语法" class="headerlink" title="5 Shell基础语法"></a>5 Shell基础语法</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#  命令  选项  参数   三部分组成</span>
ls <span class="token operator">-</span>a  <span class="token operator">/</span>temp      
ls <span class="token operator">-</span><span class="token operator">-</span>all
<span class="token comment" spellcheck="true"># 以下三个一样</span>
ls <span class="token operator">-</span>l <span class="token operator">-</span>a
ls <span class="token operator">-</span>la
ls <span class="token operator">-</span>al</code></pre>
<h3 id="6-命令补全"><a href="#6-命令补全" class="headerlink" title="6 命令补全"></a>6 命令补全</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># 一下或者两下tab建</span>
<span class="token comment" spellcheck="true"># 一下的话会直接找到你要用的命令</span>
<span class="token comment" spellcheck="true"># 两下，可能会用到的全列出来</span>

<span class="token comment" spellcheck="true"># ifconfig 在7的版本没有，需要装软件</span>
yum insatll net<span class="token operator">-</span>tools <span class="token operator">-</span>y
yum insatll net<span class="token operator">-</span>tools

<span class="token comment" spellcheck="true"># yum install bash-completion -y   补齐选项</span>
ls <span class="token operator">-</span> 两下tab建，所有的选项都会提示出来
</code></pre>
<h3 id="7-命令快捷键"><a href="#7-命令快捷键" class="headerlink" title="7 命令快捷键"></a>7 命令快捷键</h3><pre class=" language-python"><code class="language-python">Ctrl <span class="token operator">+</span> a    <span class="token comment" spellcheck="true">#光标跳转至正在输入的命令行的首部</span>
Ctrl <span class="token operator">+</span> e    <span class="token comment" spellcheck="true">#光标跳转至正在输入的命令行的尾部</span>
Ctrl <span class="token operator">+</span> c    <span class="token comment" spellcheck="true">#终止前台运行的程序   ##################</span>
Ctrl <span class="token operator">+</span> d    <span class="token comment" spellcheck="true">#在shell中，ctrl-d表示推出当前shell。</span>
Ctrl <span class="token operator">+</span> z    <span class="token comment" spellcheck="true">#将任务暂停，挂至后台</span>
Ctrl <span class="token operator">+</span> l    <span class="token comment" spellcheck="true">#清屏，和clear命令等效。  ##############</span>
Ctrl <span class="token operator">+</span> k    <span class="token comment" spellcheck="true">#删除从光标到行末的所有字符</span>
Ctrl <span class="token operator">+</span> u    <span class="token comment" spellcheck="true">#删除从光标到行首的所有字符</span>
Ctrl <span class="token operator">+</span> r    <span class="token comment" spellcheck="true">#搜索历史命令, 利用关键字，Tab建选中,只能找到最近的一条</span>
Ctrl <span class="token operator">+</span> w    <span class="token comment" spellcheck="true">#按单词或空格进行向前删除</span>
Ctrl <span class="token operator">+</span> 左右建 <span class="token comment" spellcheck="true">#按单词或空格进行向前向后跳</span>

<span class="token comment" spellcheck="true">#在命令行前加面加 "#" 则该命令不会被执行</span></code></pre>
<h3 id="8-history"><a href="#8-history" class="headerlink" title="8 history"></a>8 history</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># history查看历史命令</span>
<span class="token comment" spellcheck="true"># !数字   快速执行数字那一行</span>
<span class="token comment" spellcheck="true"># !yum    快速执行最近一条yum命令</span>


<span class="token comment" spellcheck="true"># history -d 70  把历史记录的第70行删除</span>
<span class="token comment" spellcheck="true"># history -c   清空所有记录（连到人家服务器，操作完了，执行一下）</span>
<span class="token comment" spellcheck="true"># history -w   可以把 历史记录写到用户家路径的.bash_history文件中</span>
</code></pre>
<h3 id="9-网络问题"><a href="#9-网络问题" class="headerlink" title="9 网络问题"></a>9 网络问题</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># 如果出现pingip可以但是ping百度不行，重启一下网络即可</span>

service network restart</code></pre>
<h2 id="三、linux基本命令"><a href="#三、linux基本命令" class="headerlink" title="三、linux基本命令"></a>三、linux基本命令</h2><h3 id="1-命令别名"><a href="#1-命令别名" class="headerlink" title="1 命令别名"></a>1 命令别名</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># 1 定义一个临时别名,ck查看目录下的所有文件</span>
alias ck <span class="token operator">=</span> <span class="token string">'ls -a'</span>

<span class="token comment" spellcheck="true"># 2 删除临时别名</span>
unalias ck

<span class="token comment" spellcheck="true"># 3 永久生效别名（需要将别名的配置写到配置文件中）</span>
echo <span class="token string">'alias ck="ls -a"'</span> <span class="token operator">>></span> <span class="token operator">/</span>etc<span class="token operator">/</span>bashrc</code></pre>
<h3 id="2-–help帮助"><a href="#2-–help帮助" class="headerlink" title="2 –help帮助"></a>2 –help帮助</h3><pre class=" language-python"><code class="language-python"><span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ls --help</span>
用法<span class="token punctuation">:</span> ls <span class="token punctuation">[</span>选项<span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">[</span>文件<span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

<span class="token comment" spellcheck="true">#ls 常见选项</span>
<span class="token operator">-</span>a  <span class="token comment" spellcheck="true">#查看目录下的所有文件，包括隐藏文件</span>
<span class="token operator">-</span>l  <span class="token comment" spellcheck="true">#以长格式的方式显示文件的详细内容</span>
<span class="token operator">-</span>h  <span class="token comment" spellcheck="true">#以人性化的方式显示内容，配合-l使用</span>
<span class="token operator">-</span>d  <span class="token comment" spellcheck="true">#只列出目录名，不列出目录以下的内容</span>
<span class="token operator">-</span>t  <span class="token comment" spellcheck="true">#按修改时间进行排序</span>
<span class="token operator">-</span>i  <span class="token comment" spellcheck="true">#显示文件的inode(该文件在该分区的一个编号)</span>


<span class="token comment" spellcheck="true"># man ls    #查看ls命令的手册</span></code></pre>
<h3 id="3-目录介绍"><a href="#3-目录介绍" class="headerlink" title="3 目录介绍"></a>3 目录介绍</h3><pre class=" language-python"><code class="language-python"><span class="token number">1</span> linux 是单根 <span class="token operator">/</span> 根路径，windows是多根
<span class="token number">2</span> bin和sbin：bin普通用户命令，超级用户命令  都是usr下的文件夹软链接到根路径
<span class="token number">3</span> home 、root：home普通用户的家路径，home下的用户名的文件夹
    <span class="token operator">-</span>用户一登录系统，是在自己的家路径 jack<span class="token operator">-</span><span class="token operator">-</span>》<span class="token operator">/</span>home<span class="token operator">/</span>jack</code></pre>
<h4 id="1-目录之usr"><a href="#1-目录之usr" class="headerlink" title="1 目录之usr"></a>1 目录之usr</h4><pre class=" language-python"><code class="language-python"><span class="token operator">/</span>usr，相当于C<span class="token punctuation">:</span>Windows
<span class="token operator">/</span>usr<span class="token operator">/</span>local，软件安装的目录，相当于C<span class="token punctuation">:</span>Program
<span class="token operator">/</span>usr<span class="token operator">/</span>bin<span class="token operator">/</span>，普通用户使用的应用程序<span class="token punctuation">(</span>重要<span class="token punctuation">)</span>
<span class="token operator">/</span>usr<span class="token operator">/</span>sbin，管理员使用的应用程序<span class="token punctuation">(</span>重要<span class="token punctuation">)</span>
<span class="token operator">/</span>usr<span class="token operator">/</span>lib，库文件Glibc 32bit
<span class="token operator">/</span>usr<span class="token operator">/</span>lib64，库文件Glibc 64bit

<span class="token number">1</span> df <span class="token operator">-</span>h  <span class="token comment" spellcheck="true"># 查看系统中文件的使用情况</span>
<span class="token number">2</span> du <span class="token operator">-</span>sh <span class="token operator">/</span>usr<span class="token operator">/</span>  <span class="token comment" spellcheck="true">#查看当前目录下各个文件及目录占用空间大小</span>



<span class="token comment" spellcheck="true"># 补充：远程执行ssh命令：</span>
<span class="token comment" spellcheck="true"># ansiable：python写的，批量执行命令（速度比较慢，大量的主机，会卡顿）</span>
<span class="token comment" spellcheck="true"># salstack：在客户端装agent，</span>
<span class="token comment" spellcheck="true"># zabbix：监控，php写的，监控mysql运行情况</span>

<span class="token comment" spellcheck="true"># /boot</span>
存放的系统启动相关的文件，例如<span class="token punctuation">:</span>kernel，grub<span class="token punctuation">(</span>引导装载程序<span class="token punctuation">)</span></code></pre>
<h4 id="2-目录之etc"><a href="#2-目录之etc" class="headerlink" title="2 目录之etc"></a>2 目录之etc</h4><pre class=" language-python"><code class="language-python"><span class="token operator">/</span>etc，极其重要，后续所有服务的配置都在这个目录中
<span class="token operator">/</span>etc<span class="token operator">/</span>sysconfig<span class="token operator">/</span>network<span class="token operator">-</span>script<span class="token operator">/</span>ifcfg<span class="token operator">-</span>，网络配置文件
<span class="token operator">/</span>etc<span class="token operator">/</span>hostname，系统主机名配置文件<span class="token punctuation">,</span>主机名很重要，有些特殊服务要依赖主机名，没有主机名会报错起不来；修改了要重启：reboot
<span class="token operator">/</span>etc<span class="token operator">/</span>resolv<span class="token punctuation">.</span>conf，dns客户端配置文件<span class="token punctuation">,</span>域名解析服务器，一般我们不配置，因为网卡的配置好了，会覆盖掉它，网卡的优先级高
<span class="token operator">/</span>etc<span class="token operator">/</span>hosts，本地域名解析配置文件，域名解析，先找自己的hosts，再去域名解析</code></pre>
<h4 id="3-目录之var-dev"><a href="#3-目录之var-dev" class="headerlink" title="3 目录之var dev"></a>3 目录之var dev</h4><pre class=" language-python"><code class="language-python"><span class="token number">1</span> cat <span class="token operator">/</span>var<span class="token operator">/</span>log<span class="token operator">/</span>secure <span class="token comment" spellcheck="true">#查看用户登陆时间</span>

<span class="token operator">/</span>dev，存放设备文件，比如硬盘，硬盘分区，光驱，等等
<span class="token operator">/</span>dev<span class="token operator">/</span>sd 硬盘设备
<span class="token operator">/</span>dev<span class="token operator">/</span>null，黑洞设备，只进不出。类似于垃圾回收站
<span class="token operator">/</span>dev<span class="token operator">/</span>random，生成随机数的设备
<span class="token operator">/</span>dev<span class="token operator">/</span>zero，能远远不断的产生数据，类似于取款机，随时随地取钱</code></pre>
<h4 id="4-目录之proc"><a href="#4-目录之proc" class="headerlink" title="4 目录之proc"></a>4 目录之proc</h4><pre class=" language-python"><code class="language-python"><span class="token operator">/</span>proc，反映系统当前进程的实时状态 <span class="token punctuation">:</span>process
加上跑着一个uwsgi<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span>》id号，重启，id号会变，<span class="token number">1</span>这个永远不变


<span class="token comment" spellcheck="true">#1 media:提供设备的挂载点，媒体文件</span>
<span class="token comment" spellcheck="true"># linux 新增了盘符，需要手动挂载</span>
<span class="token comment" spellcheck="true"># 把光盘里的数据，挂载到media目录</span>
mount  <span class="token operator">/</span>dev<span class="token operator">/</span>cdrom <span class="token operator">/</span>media<span class="token operator">/</span>

<span class="token comment" spellcheck="true"># 2 mnt：提供设备的挂载点（同上）</span>

<span class="token comment" spellcheck="true"># 3 opt：第三方工具，第三方软件默认安装的(mysql...)</span>

<span class="token comment" spellcheck="true"># run :下有pid，log结尾的文件</span>
ls <span class="token operator">/</span>run
cat sshd<span class="token punctuation">.</span>pid  <span class="token comment" spellcheck="true"># 进程运行的pid号,放在文件中</span>
ps aux <span class="token operator">|</span>grep sshd

<span class="token comment" spellcheck="true"># .lock文件的作用,锁机制</span>
<span class="token comment" spellcheck="true"># 假设现在执行</span>
yum install tree
<span class="token comment" spellcheck="true"># 再开一个窗口执行相同命令</span>
yum install tree
<span class="token triple-quoted-string string">'''
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  71 M RSS (470 MB VSZ)
    Started: Tue Aug 18 00:26:31 2020 - 00:24 ago
    State  : Sleeping, pid: 6191
'''</span>
cat <span class="token operator">/</span>run<span class="token operator">/</span>yum<span class="token punctuation">.</span>pid</code></pre>
<h3 id="4-文件管理"><a href="#4-文件管理" class="headerlink" title="4 文件管理"></a>4 文件管理</h3><h4 id="1-创建"><a href="#1-创建" class="headerlink" title="1 创建"></a>1 创建</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># touch 文件创建</span>
<span class="token comment" spellcheck="true"># 无则创建，有则修改更新时间</span>

touch file
touch <span class="token operator">/</span>home<span class="token operator">/</span>od<span class="token operator">/</span>file1 file2  <span class="token comment" spellcheck="true"># home和od都必须存在</span>
touch file｛a，b，c｝


<span class="token comment" spellcheck="true"># mkdir 目录创建</span>
<span class="token comment" spellcheck="true"># 选项：-v 显示详细信息  -p 递归创建目录</span>
<span class="token comment" spellcheck="true"># mkdir dir1</span>
<span class="token comment" spellcheck="true"># mkdir /home/od/dir1 /home/od/dir2</span>
<span class="token comment" spellcheck="true"># mkdir -v /home/od/{dir3,dir4} </span>
<span class="token comment" spellcheck="true"># mkdir -pv /home/od/dir5/dir6</span>
<span class="token comment" spellcheck="true"># mkdir -pv /home/{od/{diu,but},boy}</span></code></pre>
<h4 id="2-查看"><a href="#2-查看" class="headerlink" title="2 查看"></a>2 查看</h4><pre class=" language-python"><code class="language-python"><span class="token number">1</span> ls

<span class="token number">2</span> <span class="token comment" spellcheck="true"># 选项: -L: 显示目录树的层级</span>
<span class="token comment" spellcheck="true"># tree /home/od/    #显示当前目录下的结构</span>
<span class="token operator">/</span>home<span class="token operator">/</span>od<span class="token operator">/</span>
├── but
├── dir1
├── dir2
├── dir3
├── dir4
├── dir5
│   └── dir6
└── diu</code></pre>
<h4 id="3-复制"><a href="#3-复制" class="headerlink" title="3 复制"></a>3 复制</h4><pre class=" language-python"><code class="language-python">cp
<span class="token comment" spellcheck="true">#选项： -v:详细显示命令执行的操作 -r: 递归处理目录与子目录 -p: 保留源文件或目录的属性</span>

<span class="token comment" spellcheck="true"># cp file /tmp/file_copy</span>
<span class="token comment" spellcheck="true"># cp name /tmp/name         #不修改名称</span>
<span class="token comment" spellcheck="true"># cp file /tmp/             #不修改名称</span>
<span class="token comment" spellcheck="true"># cp -p file /tmp/file_p    #-p保持原文件或目录的属性</span>
<span class="token comment" spellcheck="true"># cp -r  /etc/ /tmp/        #复制目录需要使用-r参数, 递归复制</span>
<span class="token comment" spellcheck="true"># cp -rv /etc/hosts /etc/hostname /tmp  #拷贝多个文件至一个目录</span>
<span class="token comment" spellcheck="true"># cp -rv /etc/{hosts,hosts.bak}</span>
<span class="token comment" spellcheck="true"># cp -rv /etc/hosts{,-org}</span></code></pre>
<h4 id="4-移动"><a href="#4-移动" class="headerlink" title="4 移动"></a>4 移动</h4><pre><code>mv
# mv file file1             #原地移动算改名
# mv file1 /tmp/            #移动文件至tmp目录
# mv /tmp/file1 ./          #移动tmp目录的文件至当前目录
# mv dir/ /tmp/             #移动目录至/tmp目录下

# touch file&#123;1..3&#125;
# mv file1 file2 file3 /opt/    #移动多个文件或至同一个目录

# mkdir dir&#123;1..3&#125;
# mv dir1/ dir2/ dir3/ /opt     #移动多个目录至同一个目录</code></pre>
<h4 id="5-删除"><a href="#5-删除" class="headerlink" title="5 删除"></a>5 删除</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#选项：-r: 递归 -f: 强制删除 -v: 详细过程</span>
<span class="token comment" spellcheck="true"># rm  file.txt      #删除文件, 默认rm存在alias别名，rm -i所以会提醒是否删除文件</span>
<span class="token comment" spellcheck="true"># rm -f file.txt    #删除文件, 不提醒</span>


<span class="token comment" spellcheck="true"># rm -r dir/        #递归删除目录，会提示</span>
<span class="token comment" spellcheck="true"># rm -rf dir/       #强制删除目录,不提醒(慎用)</span>


<span class="token comment" spellcheck="true">#1.rm删除示例</span>
<span class="token comment" spellcheck="true"># mkdir /home/dir10</span>
<span class="token comment" spellcheck="true"># touch /home/dir10/{file2,file3,.file4}</span>
<span class="token comment" spellcheck="true"># rm -f /home/dir10/  //不包括隐藏文件 </span>
<span class="token comment" spellcheck="true"># ls /home/dir10/ -a</span>
<span class="token punctuation">.</span> <span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token punctuation">.</span>file4


<span class="token comment" spellcheck="true">#2.rm删除示例2</span>
<span class="token comment" spellcheck="true"># touch file{1..10}</span>
<span class="token comment" spellcheck="true"># touch {1..10}.pdf</span>
<span class="token comment" spellcheck="true"># rm -rf file </span>
<span class="token comment" spellcheck="true"># rm -rf .pdf</span></code></pre>
<h4 id="6-查看文件内容cat"><a href="#6-查看文件内容cat" class="headerlink" title="6 查看文件内容cat"></a>6 查看文件内容cat</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#------cat</span>
<span class="token comment" spellcheck="true"># cp /etc/passwd ./pass</span>
<span class="token comment" spellcheck="true"># cat pass      #正常查看文件方式</span>
<span class="token comment" spellcheck="true"># cat -n pass   #-n显示文件有多少行</span>
<span class="token comment" spellcheck="true"># cat -A pass   #查看文件的特殊符号,比如文件中存在tab键</span>
<span class="token comment" spellcheck="true"># tac pass      #倒序查看文件</span>
cat <span class="token operator">>></span> test2<span class="token punctuation">.</span>txt <span class="token operator">&lt;&lt;</span>EOF
ads
adf
EOF</code></pre>
<h4 id="7-查看文件内容less，more"><a href="#7-查看文件内容less，more" class="headerlink" title="7 查看文件内容less，more"></a>7 查看文件内容less，more</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#------less、more</span>
<span class="token comment" spellcheck="true"># less /etc/services    #使用光标上下翻动，空格进行翻页，q退出</span>
<span class="token comment" spellcheck="true"># more /etc/services    #使用回车上下翻动，空格进行翻页，q退出(有百分比)</span></code></pre>
<h4 id="8-查看文件头head，尾tail"><a href="#8-查看文件头head，尾tail" class="headerlink" title="8 查看文件头head，尾tail"></a>8 查看文件头head，尾tail</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#------head</span>
<span class="token comment" spellcheck="true"># head pass     #查看头部内容，默认前十行</span>
<span class="token comment" spellcheck="true"># head -n5 pass #查看头部5行，使用-n指定</span>
<span class="token comment" spellcheck="true"># ps aux | head -5 # 只看头部5个进程</span>

<span class="token comment" spellcheck="true">#------tail</span>
<span class="token comment" spellcheck="true"># tail pass  # 查看文件尾部，默认10行</span>
<span class="token comment" spellcheck="true"># tail -20 /var/log/secure  # 查看文件尾部20行</span>
<span class="token comment" spellcheck="true"># tail -f /var/log/messages #-f动态查看文件尾部的变化</span>
<span class="token comment" spellcheck="true"># tailf /var/log/messages   #查看文件尾部的变化</span>
<span class="token comment" spellcheck="true"># ps aux | tail -2</span></code></pre>
<h4 id="9-过滤文件"><a href="#9-过滤文件" class="headerlink" title="9 过滤文件"></a>9 过滤文件</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#------grep过滤文件内容</span>
<span class="token comment" spellcheck="true"># grep "^root" pass     #匹配以root开头的行</span>
<span class="token comment" spellcheck="true"># grep "bash$" pass     #匹配以bash结尾的行</span>
<span class="token comment" spellcheck="true"># grep -i "ftp" pass    #忽略大小写匹配</span>
<span class="token comment" spellcheck="true"># grep  -Ei "sync$|ftp" pass    #匹配文件中包含sync结尾或ftp字符串</span>
<span class="token comment" spellcheck="true"># grep -n -A 2 "Failed" /var/log/secure #匹配/var/log/secure文件中Failed字符串,并打印它的下2行</span>
<span class="token comment" spellcheck="true"># grep -n -B 2 "Failed" /var/log/secure #匹配/var/log/secure文件中Failed字符串,并打印它的上2行</span>
<span class="token comment" spellcheck="true"># grep -n -C 2 "Failed" /var/log/secure #匹配/var/log/secure文件中Failed字符串,并打印它的上下2行</span>

<span class="token comment" spellcheck="true"># 上翻，下翻</span>
control<span class="token operator">+</span>b：下翻
control<span class="token operator">+</span>f：上翻</code></pre>
<h4 id="10-联网下载文件"><a href="#10-联网下载文件" class="headerlink" title="10 联网下载文件"></a>10 联网下载文件</h4><pre class=" language-python"><code class="language-python">yum install wget <span class="token operator">-</span>y
<span class="token comment" spellcheck="true">#选项: -O: 指定下载地址</span>
<span class="token comment" spellcheck="true"># wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo</span>
<span class="token comment" spellcheck="true"># 比如下载图片</span>


<span class="token comment" spellcheck="true"># crul：浏览网络上资源，-o保存到本地</span>
<span class="token comment" spellcheck="true">#选项: -o: 指定下载地址</span>
<span class="token comment" spellcheck="true"># curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo</span>
<span class="token comment" spellcheck="true"># 请求网址得到的是页面的html地址类似request模块</span></code></pre>
<h4 id="11-本地上传下载"><a href="#11-本地上传下载" class="headerlink" title="11 本地上传下载"></a>11 本地上传下载</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># yum install lrzsz -y  #不安装软件则无法执行该命令</span>

<span class="token comment" spellcheck="true"># rz            #只能上传文件文件上传(不能大于4g)</span>
<span class="token comment" spellcheck="true"># sz /path/file #只能下载文件</span></code></pre>
<h4 id="12-文件查找"><a href="#12-文件查找" class="headerlink" title="12 文件查找"></a>12 文件查找</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># locate /etc/sh       #搜索etc目录下所有以sh开头的文件</span>
<span class="token comment" spellcheck="true"># locate -i /etc/sh    #搜索etc目录下，所有以sh开头的文件，忽略大小写</span></code></pre>
<h4 id="13-命令查找"><a href="#13-命令查找" class="headerlink" title="13 命令查找"></a>13 命令查找</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># which ls  #查找ls命令的绝对路径</span>

<span class="token comment" spellcheck="true"># whereis ls       //查找命令的路径、帮助手册、等</span>
<span class="token comment" spellcheck="true"># whereis -b ls    //仅显示命令所在的路径，仅看二进制</span>

<span class="token comment" spellcheck="true"># 对于内核相关的一些命令，用which whereis 是无法查询到的，需要使用type采查询</span>
<span class="token comment" spellcheck="true"># type -a ls        #查看命令的绝对路径(包括别名)</span>
<span class="token comment" spellcheck="true"># type -a for</span>
</code></pre>
<h4 id="14-文件字符处理"><a href="#14-文件字符处理" class="headerlink" title="14 文件字符处理"></a>14 文件字符处理</h4><pre class=" language-python"><code class="language-python">sort 排序
uniq 去重
cut 截断
wc 统计行号
http<span class="token punctuation">:</span><span class="token operator">//</span>liuqingzheng<span class="token punctuation">.</span>top<span class="token operator">/</span>linux<span class="token operator">/</span><span class="token operator">%</span>E5<span class="token operator">%</span><span class="token number">85</span><span class="token operator">%</span>A5<span class="token operator">%</span>E9<span class="token operator">%</span><span class="token number">97</span><span class="token operator">%</span>A8<span class="token operator">%</span>E5<span class="token operator">%</span><span class="token number">88</span><span class="token operator">%</span>B0<span class="token operator">%</span>E7<span class="token operator">%</span>B2<span class="token operator">%</span>BE<span class="token operator">%</span>E9<span class="token operator">%</span><span class="token number">80</span><span class="token operator">%</span><span class="token number">9A</span><span class="token operator">/</span><span class="token number">04</span><span class="token operator">-</span>Linux<span class="token operator">%</span>E6<span class="token operator">%</span><span class="token number">96</span><span class="token operator">%</span><span class="token number">87</span><span class="token operator">%</span>E4<span class="token operator">%</span>BB<span class="token operator">%</span>B6<span class="token operator">%</span>E7<span class="token operator">%</span>AE<span class="token operator">%</span>A1<span class="token operator">%</span>E7<span class="token operator">%</span><span class="token number">90</span><span class="token operator">%</span><span class="token number">86</span><span class="token operator">/</span></code></pre>
<h4 id="15-系统文件属性"><a href="#15-系统文件属性" class="headerlink" title="15 系统文件属性"></a>15 系统文件属性</h4><pre class=" language-python"><code class="language-python"><span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ls -l ks.cfg</span>
<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ll -h ks.cfg</span>
<span class="token operator">-</span>rw<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token punctuation">.</span> <span class="token number">1</span> root root <span class="token number">4434</span> May <span class="token number">30</span> <span class="token number">13</span><span class="token punctuation">:</span><span class="token number">58</span> ks<span class="token punctuation">.</span>cfg

<span class="token comment" spellcheck="true">#</span>
<span class="token operator">-</span>rw<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token punctuation">.</span> ①<span class="token punctuation">:</span>第一个字符是文件类型，其他则是权限
<span class="token number">1</span>           ②<span class="token punctuation">:</span>硬链接次数
root        ③<span class="token punctuation">:</span>文件属于哪个用户
root        ④<span class="token punctuation">:</span>文件属于哪个组（用户的分组）
<span class="token number">4434</span>        ⑤<span class="token punctuation">:</span>文件大小
May30 <span class="token number">13</span><span class="token punctuation">:</span><span class="token number">58</span> ⑥⑦⑧<span class="token punctuation">:</span>最新修改的时间与日期
ks<span class="token punctuation">.</span>cfg      ⑨<span class="token punctuation">:</span>文件或目录名称


<span class="token comment" spellcheck="true"># 文件类型解析</span>
<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ll -d /etc/hosts /tmp /bin/ls  /dev/sda /dev/tty1 /etc/grub2.cfg /dev/log /run/dmeventd-client</span>
<span class="token operator">-</span>rwxr<span class="token operator">-</span>xr<span class="token operator">-</span>x<span class="token punctuation">.</span>  <span class="token number">1</span> root root <span class="token number">117656</span> Jun <span class="token number">30</span>  <span class="token number">2016</span> <span class="token operator">/</span>bin<span class="token operator">/</span>ls
srw<span class="token operator">-</span>rw<span class="token operator">-</span>rw<span class="token operator">-</span><span class="token punctuation">.</span>  <span class="token number">1</span> root root      <span class="token number">0</span> Jan <span class="token number">20</span> <span class="token number">10</span><span class="token punctuation">:</span><span class="token number">35</span> <span class="token operator">/</span>dev<span class="token operator">/</span>log
brw<span class="token operator">-</span>rw<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token punctuation">.</span>  <span class="token number">1</span> root disk   <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">0</span> Jan <span class="token number">20</span> <span class="token number">10</span><span class="token punctuation">:</span><span class="token number">36</span> <span class="token operator">/</span>dev<span class="token operator">/</span>sda
crw<span class="token operator">-</span><span class="token operator">-</span>w<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token punctuation">.</span>  <span class="token number">1</span> root tty    <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">1</span> Jan <span class="token number">20</span> <span class="token number">10</span><span class="token punctuation">:</span><span class="token number">36</span> <span class="token operator">/</span>dev<span class="token operator">/</span>tty1
lrwxrwxrwx<span class="token punctuation">.</span>  <span class="token number">1</span> root root     <span class="token number">22</span> Jan <span class="token number">13</span> <span class="token number">11</span><span class="token punctuation">:</span><span class="token number">31</span> <span class="token operator">/</span>etc<span class="token operator">/</span>grub2<span class="token punctuation">.</span>cfg <span class="token operator">-</span><span class="token operator">></span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token operator">/</span>boot<span class="token operator">/</span>grub2<span class="token operator">/</span>grub<span class="token punctuation">.</span>cfg
<span class="token operator">-</span>rw<span class="token operator">-</span>r<span class="token operator">-</span><span class="token operator">-</span>r<span class="token operator">-</span><span class="token operator">-</span><span class="token punctuation">.</span>  <span class="token number">1</span> root root    <span class="token number">199</span> Jan <span class="token number">20</span> <span class="token number">11</span><span class="token punctuation">:</span><span class="token number">03</span> <span class="token operator">/</span>etc<span class="token operator">/</span>hosts
prw<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token punctuation">.</span>  <span class="token number">1</span> root root      <span class="token number">0</span> Jan <span class="token number">20</span> <span class="token number">10</span><span class="token punctuation">:</span><span class="token number">36</span> <span class="token operator">/</span>run<span class="token operator">/</span>dmeventd<span class="token operator">-</span>client
drwxrwxrwt<span class="token punctuation">.</span> <span class="token number">61</span> root root   <span class="token number">8192</span> Jan <span class="token number">21</span> <span class="token number">13</span><span class="token punctuation">:</span><span class="token number">01</span> <span class="token operator">/</span>tmp

<span class="token comment" spellcheck="true">#说明</span>
<span class="token operator">-</span>   <span class="token comment" spellcheck="true">#普通文件(文本, 二进制, 压缩, 图片, 日志等) </span>
d   <span class="token comment" spellcheck="true">#目录文件</span>
b   <span class="token comment" spellcheck="true">#设备文件(块设备)存储设备硬盘 /dev/sda1, /dev/sda2</span>
c   <span class="token comment" spellcheck="true">#设备文件(字符设备)，终端 /dev/tty1, /dev/zero</span>
s   <span class="token comment" spellcheck="true">#套接字文件, 进程间通信(socket)</span>
p   <span class="token comment" spellcheck="true">#管道文件</span>
l   <span class="token comment" spellcheck="true">#链接文件</span>

<span class="token comment" spellcheck="true"># 但是有时候这样给的文件类型不太精确，我们可以file来判断这个文件的类型</span>
<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># file /etc/hosts</span>
<span class="token operator">/</span>etc<span class="token operator">/</span>hosts<span class="token punctuation">:</span> ASCII text

<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># file /bin/ls</span>
<span class="token operator">/</span>bin<span class="token operator">/</span>ls<span class="token punctuation">:</span> ELF <span class="token number">64</span><span class="token operator">-</span>bit LSB executable<span class="token punctuation">,</span> x86<span class="token number">-64</span><span class="token punctuation">,</span> version <span class="token number">1</span> <span class="token punctuation">(</span>SYSV<span class="token punctuation">)</span><span class="token punctuation">,</span> dynamically linked <span class="token punctuation">(</span>uses shared libs<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">for</span> GNU<span class="token operator">/</span>Linux <span class="token number">2.6</span><span class="token punctuation">.</span><span class="token number">32</span><span class="token punctuation">,</span> BuildID<span class="token punctuation">[</span>sha1<span class="token punctuation">]</span><span class="token operator">=</span>aa7ff68f13de25936a098016243ce57c3c982e06<span class="token punctuation">,</span> stripped

<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># file /dev/sda</span>
<span class="token operator">/</span>dev<span class="token operator">/</span>sda<span class="token punctuation">:</span> block special

<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># file /dev/tty1</span>
<span class="token operator">/</span>dev<span class="token operator">/</span>tty1<span class="token punctuation">:</span> character special

<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># file /etc/grub2.cfg</span>
<span class="token operator">/</span>etc<span class="token operator">/</span>grub2<span class="token punctuation">.</span>cfg<span class="token punctuation">:</span> broken symbolic link to `<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token operator">/</span>boot<span class="token operator">/</span>grub2<span class="token operator">/</span>grub<span class="token punctuation">.</span>cfg'

<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># file /home</span>
<span class="token operator">/</span>home<span class="token punctuation">:</span> directory

<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># file /run/dmeventd-client</span>
<span class="token operator">/</span>run<span class="token operator">/</span>dmeventd<span class="token operator">-</span>client<span class="token punctuation">:</span> fifo <span class="token punctuation">(</span>named pipe<span class="token punctuation">)</span>

<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ll but</span>
<span class="token operator">-</span>rw<span class="token operator">-</span>r<span class="token operator">-</span><span class="token operator">-</span>r<span class="token operator">-</span><span class="token operator">-</span> <span class="token number">1</span> root root <span class="token number">42125</span> Apr  <span class="token number">1</span> <span class="token number">12</span><span class="token punctuation">:</span><span class="token number">26</span> but
<span class="token punctuation">[</span>root@lqz <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># file but</span>
but<span class="token punctuation">:</span> Zip archive data<span class="token punctuation">,</span> at least v1<span class="token number">.0</span> to extract</code></pre>
<h4 id="16-系统链接文件"><a href="#16-系统链接文件" class="headerlink" title="16 系统链接文件"></a>16 系统链接文件</h4><p>文件有文件名与数据，在Linux上被分成两个部分：用户数据 (user data) 与元数据 (metadata)。<br>用户数据，即文件数据块 (data block)，数据块是记录文件真实内容的地方，我们将其称为Block<br>元数据，即文件的附加属性，如文件大小、创建时间、所有者等信息。我们称其为Inode<br>在Linux中，inode是文件元数据的一部分但其并不包含文件名，inode号即索引节点号）<br>文件名仅是为了方便人们的记忆和使用，系统或程序通过 inode 号寻找正确的文件数据块。图1.展示了程序通过文件名获取文件内容的过程。</p>
<p>Linux 系统引入了两种链接：硬链接 (hard link) 与软链接（又称符号链接，即 soft link 或 symbolic link）</p>
<p>ll -i 查看inode</p>
<h5 id="16-1软连接"><a href="#16-1软连接" class="headerlink" title="16.1软连接"></a>16.1软连接</h5><p>软链接相当于Windows的快捷方式，软链接文件会将inode指向源文件的block，当我们访问这个软链接文件时，其实访问的是源文件本身。那么当我们对一个文件创建多个软链接，其实就是多个inode指向同一个block。当我们删除软链接文件时，其实只是删除了一个inode指向，并不会对源文件源文件造成影响，但如果删除的是源文件则会造成所有软链接文件失效。</p>
<pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#文件软链接示例</span>
touch <span class="token operator">/</span>root<span class="token operator">/</span>file
ln <span class="token operator">-</span>s <span class="token operator">/</span>root<span class="token operator">/</span>file <span class="token operator">/</span>tmp<span class="token operator">/</span>file_bak
ll <span class="token operator">/</span>tmp<span class="token operator">/</span>file_bak  <span class="token operator">//</span>root下file链接到<span class="token operator">/</span>tmp下并重命名为file_bak


<span class="token comment" spellcheck="true">#目录软链接示例</span>
mkdir <span class="token operator">/</span>soft<span class="token operator">/</span>nginx1<span class="token number">.1</span> <span class="token operator">-</span>p
ln <span class="token operator">-</span>s <span class="token operator">/</span>soft<span class="token operator">/</span>nginx1<span class="token number">.1</span><span class="token operator">/</span> <span class="token operator">/</span>soft<span class="token operator">/</span>nginx
ll <span class="token operator">/</span>soft<span class="token operator">/</span>nginx   <span class="token operator">//</span>查看链接指向

<span class="token comment" spellcheck="true">#软链接使用场景</span>
<span class="token number">1</span><span class="token punctuation">.</span>软件升级
<span class="token number">2</span><span class="token punctuation">.</span>企业代码发布 
<span class="token number">3</span><span class="token punctuation">.</span>不方便目录移动</code></pre>
<h5 id="16-2-硬链接"><a href="#16-2-硬链接" class="headerlink" title="16.2 硬链接"></a>16.2 硬链接</h5><p>若一个inode号对应多个文件名，则称这些文件为硬链接。换言之，硬链接就是同一个文件使用了多个别名，如下图hard link 就是 file 的一个别名，他们有共同的 inode。</p>
<pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#文件硬链接示例</span>
ln  <span class="token operator">/</span>root<span class="token operator">/</span>file <span class="token operator">/</span>tmp<span class="token operator">/</span>file_hard
ll <span class="token operator">/</span>tmp<span class="token operator">/</span>file_hard

<span class="token comment" spellcheck="true">#PS：目录不能创建硬链接，硬链接文件可以用rm命令删除</span></code></pre>
<p>5.硬链接与软链接区别<br>1)ln命令创建硬链接，ln -s命令创建软链接。<br>2)目录不能创建硬链接，并且硬链接不可以跨越分区系统。<br>3)目录软链接特别常用,并且软链接支持跨越分区系统。<br>4)硬链接文件与源文件的inode相同，软链接文件与源文件inode不同。<br>5)删除软链接文件，对源文件及硬链接文件无任何影响。<br>6)删除文件的硬链接文件，对源文件及链接文件无任何影响。<br>7)删除链接文件的源文件，对硬链接无影响，会导致软链接失效。<br>8)删除源文件及其硬链接文件，整个文件会被真正的删除。</p>
<h3 id="5-读写文件"><a href="#5-读写文件" class="headerlink" title="5 读写文件"></a>5 读写文件</h3><p><strong>vim</strong></p>
<pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># yum install vim -y</span>
<span class="token comment" spellcheck="true"># 普通模式、编辑模式、命令模式</span>
<span class="token comment" spellcheck="true"># 普通模式：</span>
    <span class="token operator">-</span>上下翻
    <span class="token operator">-</span>yy 复制一行
    <span class="token operator">-</span>p   粘贴
    <span class="token operator">-</span>dd  剪切
    <span class="token operator">-</span>p   把上面剪切的粘贴上
<span class="token comment" spellcheck="true"># 编辑模式</span>
    <span class="token operator">-</span>i：insert插入
    <span class="token operator">-</span>a：append追加
    <span class="token operator">-</span>o：换行
    <span class="token operator">-</span>正常写就可以了
    <span class="token operator">-</span>esc回到普通模式

<span class="token comment" spellcheck="true"># 命令模式：</span>
    <span class="token operator">-</span>不能从编辑模式直接进，只能先到普通模式按 <span class="token punctuation">:</span>  进入命令，退出命令模式esc
     <span class="token operator">-</span>w  表示保存
     <span class="token operator">-</span>q   退出
     <span class="token operator">-</span>！  强制退出
     <span class="token operator">-</span>修改了文件后保存：  wq    wq！
     <span class="token operator">-</span>修改了不想保存退出： q     q！
     <span class="token operator">-</span><span class="token punctuation">:</span>set nu 显示行号
     <span class="token operator">-</span><span class="token punctuation">:</span>set nonu 不显示行号
     <span class="token operator">-</span><span class="token operator">/</span>字符串    搜索这个字符串
     <span class="token operator">-</span><span class="token punctuation">:</span><span class="token operator">%</span>s<span class="token comment" spellcheck="true">#sbin#test#g #替换整个文本文件中包含sbin的替换为test</span></code></pre>
<h3 id="6-用户相关"><a href="#6-用户相关" class="headerlink" title="6 用户相关"></a>6 用户相关</h3><h4 id="1-用户与权限"><a href="#1-用户与权限" class="headerlink" title="1 用户与权限"></a>1 用户与权限</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#1  id  查看当前用户信息</span>
uid<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">(</span>root<span class="token punctuation">)</span> gid<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">(</span>root<span class="token punctuation">)</span> groups<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">(</span>root<span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">#2  用户信息保存在 cat /etc/passwd</span>
root<span class="token punctuation">:</span>x<span class="token punctuation">:</span><span class="token number">0</span><span class="token punctuation">:</span><span class="token number">0</span><span class="token punctuation">:</span>root<span class="token punctuation">:</span><span class="token operator">/</span>root<span class="token punctuation">:</span><span class="token operator">/</span>bin<span class="token operator">/</span>bash
<span class="token comment" spellcheck="true">#3  密码存放路径 cat /etc/shadow</span>
<span class="token comment" spellcheck="true">#4 约定不同用户的uid属于某个范围（了解）</span>
<span class="token comment" spellcheck="true"># 5 用户的增，删，改</span>
    <span class="token operator">-</span>useradd（一个用户只能属于一个主组，属于多个附加组）
        <span class="token operator">-</span>groupadd sa  新增一个组
        <span class="token operator">-</span>groupadd sa1  新增一个组
        <span class="token operator">-</span>groupadd students 新增一个组
        <span class="token operator">-</span>useradd <span class="token operator">-</span>u <span class="token number">5001</span> <span class="token operator">-</span>g students <span class="token operator">-</span>G sa<span class="token punctuation">,</span>sa1 <span class="token operator">-</span>c <span class="token string">"2020 new student"</span> <span class="token operator">-</span>s <span class="token operator">/</span>bin<span class="token operator">/</span>bash lqz1
    <span class="token operator">-</span>创建mysql系统用户，<span class="token operator">-</span>M不建立用户家目录 <span class="token operator">-</span>s指定nologin使其用户无法登陆系统 
       useradd mysql <span class="token operator">-</span>M <span class="token operator">-</span>s <span class="token operator">/</span>sbin<span class="token operator">/</span>nologin
    <span class="token operator">-</span>usermod
        <span class="token operator">-</span>usermod <span class="token operator">-</span>c <span class="token string">"2019 new student"</span> <span class="token operator">-</span>md <span class="token operator">/</span>bgx <span class="token operator">-</span>s <span class="token operator">/</span>bin<span class="token operator">/</span>sh <span class="token operator">-</span>l change_bgx bgx
        <span class="token operator">-</span>usermod <span class="token operator">-</span>L change_bgx  <span class="token comment" spellcheck="true">#锁定后会无法登陆系统</span>
        <span class="token operator">-</span>usermod <span class="token operator">-</span>U change_bgx
    <span class="token operator">-</span>userdel
        <span class="token operator">-</span>userdel egon  <span class="token comment" spellcheck="true"># 删除用户，不删家目录</span>
        <span class="token operator">-</span>userdel <span class="token operator">-</span>r egon1 <span class="token comment" spellcheck="true"># 删除用户，删家目录</span>

<span class="token comment" spellcheck="true">#6  改密码</span>
    <span class="token operator">-</span>passwd root
<span class="token comment" spellcheck="true">#7 组增删改</span>
    <span class="token operator">-</span>groupadd no_gid   新增组
    <span class="token operator">-</span>groupmod <span class="token operator">-</span>g <span class="token number">1111</span> student  改组id号
    <span class="token operator">-</span>groupmod student <span class="token operator">-</span>n new_student  改组名字
    <span class="token operator">-</span>groupdel new_student   删除组（组下没有人，把人删除，再删）

<span class="token comment" spellcheck="true"># 8 su 和sudo</span>
    <span class="token operator">-</span>su 切换用户
        <span class="token operator">-</span>su <span class="token operator">-</span> jack：打开新的shell，会加载自己的环境变量
        <span class="token operator">-</span>su jack：不打开新的shell，不会加载它的环境变量
    <span class="token operator">-</span>sudo 普通用户可以有一些超级用户的权限，不需要输入密码
        usermod jack <span class="token operator">-</span>G wheel  <span class="token comment" spellcheck="true"># 把jack用户加入到了wheel组</span>
        <span class="token operator">-</span>你这个用户没有权限，你尝试 sudo mkdir ll试一下，不行，超级管理员没有给你配这个权限</code></pre>
<h4 id="2-文件权限（特殊权限）"><a href="#2-文件权限（特殊权限）" class="headerlink" title="2 文件权限（特殊权限）"></a>2 文件权限（特殊权限）</h4><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#选项: + 增加权限 -减少权限 =等于某个权限</span>
<span class="token comment" spellcheck="true"># a：让文件或目录仅可追加内容</span>
<span class="token comment" spellcheck="true"># i：不得任意更动文件或目录</span>
<span class="token comment" spellcheck="true"># 给某个文件或者文件夹加特殊权限</span>
    <span class="token operator">-</span>chattr <span class="token operator">+</span>i lqz<span class="token punctuation">.</span>text    
    <span class="token operator">-</span>chattr <span class="token operator">-</span>i lqz<span class="token punctuation">.</span>text</code></pre>
<h3 id="7-压缩解压"><a href="#7-压缩解压" class="headerlink" title="7 压缩解压"></a>7 压缩解压</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#1  Windows的压缩包与Linux的压缩包能否互通</span>
    windwods：rar，zip  
    linux：tar<span class="token punctuation">.</span>gz<span class="token punctuation">,</span>zip互通，不支持rar
<span class="token comment" spellcheck="true"># 2 gzip (只能压一个文件，不能压文件夹，会把原来的删除)</span>
    <span class="token operator">-</span>gzip file
    <span class="token operator">-</span>gzip <span class="token operator">-</span>d file
    <span class="token operator">-</span>有什么用？
       <span class="token operator">-</span>cd <span class="token operator">/</span>etc<span class="token operator">/</span>yum<span class="token punctuation">.</span>repos<span class="token punctuation">.</span>d<span class="token operator">/</span>
       <span class="token comment" spellcheck="true"># 可以把文件做个备份</span>
<span class="token comment" spellcheck="true">#3 zip的压缩和解压</span>
    <span class="token operator">-</span>yum install zip unzip <span class="token operator">-</span>y
    <span class="token operator">-</span>zip  filename<span class="token punctuation">.</span>zip  filename  <span class="token comment" spellcheck="true"># 压单个文件</span>
    <span class="token operator">-</span>zip <span class="token operator">-</span>r home<span class="token punctuation">.</span>zip <span class="token operator">/</span>home<span class="token operator">/</span>   <span class="token comment" spellcheck="true">#把home文件夹压缩</span>
    <span class="token operator">-</span>unzip  home<span class="token punctuation">.</span>zip   <span class="token comment" spellcheck="true">#解压</span>
    <span class="token operator">-</span>unzip <span class="token operator">-</span>l  home<span class="token punctuation">.</span>zip <span class="token comment" spellcheck="true"># 不解压，看内容</span>
    <span class="token operator">-</span>unzip home<span class="token punctuation">.</span>zip  <span class="token operator">-</span>d <span class="token operator">/</span>opt<span class="token operator">/</span>   <span class="token comment" spellcheck="true"># 把当前路径下的home.zip 解压到opt</span>

<span class="token comment" spellcheck="true"># 4 tar打包与压缩</span>
    <span class="token operator">-</span>tar <span class="token operator">-</span>czf 压缩后的文件名 压缩前的文件名        <span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span>》tar<span class="token punctuation">.</span>gz
    <span class="token operator">-</span>tar <span class="token operator">-</span>xf  xx<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz  <span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span><span class="token operator">></span>解压xx<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz

    tar <span class="token operator">-</span>xzvf  xx<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz ：解压tar<span class="token punctuation">.</span>gz，详细过程列出来
    <span class="token comment" spellcheck="true"># 可以把不同目录的文件都压缩到一个文件内</span>
    <span class="token operator">-</span>tar <span class="token operator">-</span>czf home<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz dd<span class="token operator">/</span> lqz1 lqz2 <span class="token operator">/</span>home<span class="token operator">/</span>

    <span class="token operator">-</span>tar czf etc<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz <span class="token operator">-</span><span class="token operator">-</span>exclude<span class="token operator">=</span>etc<span class="token operator">/</span>services etc<span class="token operator">/</span>  <span class="token comment" spellcheck="true"># 排除文件</span>
    <span class="token operator">-</span>tar xf <span class="token operator">/</span>etc<span class="token operator">/</span>local<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz  <span class="token operator">-</span>C <span class="token operator">/</span>tmp  <span class="token comment" spellcheck="true"># -C指定解压到哪个路径</span>
</code></pre>
<h3 id="8-软件管理：rpm"><a href="#8-软件管理：rpm" class="headerlink" title="8 软件管理：rpm"></a>8 软件管理：rpm</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#1  红帽的软件安装包（windows的：exe，mis）</span>
<span class="token comment" spellcheck="true">#2  mount /dev/cdrom /mnt 把光盘挂在到 /mnt文件夹</span>
<span class="token comment" spellcheck="true">#3  Linux中除了rpm安装软件，是否还有安装软件方式</span>
    <span class="token operator">-</span>源码安装<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">></span>官网下源码<span class="token operator">-</span><span class="token operator">-</span>》编译安装<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">-</span>》最新
    <span class="token operator">-</span>rpm包，预先编译打包<span class="token punctuation">,</span>安装简单，yum安装，本质就是rmp安装<span class="token operator">-</span><span class="token operator">-</span>》稍微老一些
    <span class="token operator">-</span>二进制包：绿色包

    <span class="token operator">-</span>安装rpm的软件：rpm <span class="token operator">-</span>ivh tree<span class="token number">-1.6</span><span class="token punctuation">.</span><span class="token number">0</span><span class="token operator">-</span><span class="token number">10.</span>el7<span class="token punctuation">.</span>x86_64<span class="token punctuation">.</span>rpm
    <span class="token operator">-</span>强制安装：rpm <span class="token operator">-</span>ivh <span class="token operator">-</span><span class="token operator">-</span>force <span class="token operator">/</span>mnt<span class="token operator">/</span>Packages<span class="token operator">/</span>tree<span class="token number">-1.5</span><span class="token punctuation">.</span><span class="token number">3</span><span class="token operator">-</span><span class="token number">3.</span>el6<span class="token punctuation">.</span>x86_64<span class="token punctuation">.</span>rpm

    <span class="token operator">-</span>rpm <span class="token operator">-</span>q ：查看这个软件是否安装<span class="token operator">**</span><span class="token operator">**</span><span class="token operator">**</span><span class="token operator">**</span>
    <span class="token operator">-</span>rpm <span class="token operator">-</span>qa <span class="token operator">|</span>grep tr  ：列出所有安装的软件
    <span class="token operator">-</span>rpm <span class="token operator">-</span>ql <span class="token punctuation">:</span>查询指定软件包所安装的目录、文件列表rpm <span class="token operator">-</span>ql unzip <span class="token operator">**</span><span class="token operator">**</span><span class="token operator">*</span>
    <span class="token operator">-</span>rpm <span class="token operator">-</span>qc unzip<span class="token punctuation">:</span>查看这个软件的配置文件位置
    <span class="token operator">-</span>rpm <span class="token operator">-</span>qf <span class="token operator">/</span>etc<span class="token operator">/</span>pam<span class="token punctuation">.</span>d<span class="token operator">/</span>vsftpd  ：查看配置文件属于哪个软件
    <span class="token operator">-</span>rpm <span class="token operator">-</span>qlp trace<span class="token operator">-</span>cmd<span class="token number">-2.6</span><span class="token punctuation">.</span><span class="token number">0</span><span class="token operator">-</span><span class="token number">10.</span>el7<span class="token punctuation">.</span>x86_64<span class="token punctuation">.</span>rpm ：查看该软件包安装后会释放哪些文件

    <span class="token operator">-</span>使用远程地址安装：rpm <span class="token operator">-</span>ivh https<span class="token punctuation">:</span><span class="token operator">//</span>mirrors<span class="token punctuation">.</span>aliyun<span class="token punctuation">.</span>com<span class="token operator">/</span>zabbix<span class="token operator">/</span>zabbix<span class="token operator">/</span><span class="token number">3.0</span><span class="token operator">/</span>rhel<span class="token operator">/</span><span class="token number">7</span><span class="token operator">/</span>x86_64<span class="token operator">/</span>zabbix<span class="token operator">-</span>agent<span class="token number">-3.0</span><span class="token punctuation">.</span><span class="token number">8</span><span class="token operator">-</span><span class="token number">2.</span>el7<span class="token punctuation">.</span>x86_64<span class="token punctuation">.</span>rpm

    <span class="token operator">-</span>rpm <span class="token operator">-</span>Uivh  升级软件需要用  U
    <span class="token operator">-</span>rpm <span class="token operator">-</span>e zabbix<span class="token operator">-</span>agent</code></pre>
<h3 id="9-yum仓库，源"><a href="#9-yum仓库，源" class="headerlink" title="9 yum仓库，源"></a>9 yum仓库，源</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true"># 1 Yum是RedHat以及CentOS中的软件包管理器。能够通过互联网下载 .rpm 包并且安装，并可以自动处理依赖性关系，无须繁琐地一次次下载、安装</span>

<span class="token comment" spellcheck="true"># 2 cd /etc/yum.repos.d/  路径下有xx.repo 文件---》yum源</span>

<span class="token comment" spellcheck="true"># 3 换阿里云的源</span>
    wget <span class="token operator">-</span>O <span class="token operator">/</span>etc<span class="token operator">/</span>yum<span class="token punctuation">.</span>repos<span class="token punctuation">.</span>d<span class="token operator">/</span>CentOS<span class="token operator">-</span>Base<span class="token punctuation">.</span>repo https<span class="token punctuation">:</span><span class="token operator">//</span>mirrors<span class="token punctuation">.</span>aliyun<span class="token punctuation">.</span>com<span class="token operator">/</span>repo<span class="token operator">/</span>Centos<span class="token number">-7.</span>repo

<span class="token comment" spellcheck="true"># 4 配置其他源</span>
    <span class="token operator">-</span>wget <span class="token operator">-</span>O <span class="token operator">/</span>etc<span class="token operator">/</span>yum<span class="token punctuation">.</span>repos<span class="token punctuation">.</span>d<span class="token operator">/</span>epel<span class="token punctuation">.</span>repo http<span class="token punctuation">:</span><span class="token operator">//</span>mirrors<span class="token punctuation">.</span>aliyun<span class="token punctuation">.</span>com<span class="token operator">/</span>repo<span class="token operator">/</span>epel<span class="token number">-7.</span>repo
    <span class="token operator">-</span>yum install nginx 

    <span class="token operator">-</span>yum provides ipconfig  <span class="token comment" spellcheck="true"># 通过命令查软件，这个命令属于哪个软件</span>

       <span class="token operator">-</span>rpm <span class="token operator">-</span>qf `which ifconfig` <span class="token comment" spellcheck="true"># 查命令属于哪个软件，前提是该软件安装了z</span></code></pre>
<h3 id="10-文件权限chmod"><a href="#10-文件权限chmod" class="headerlink" title="10 文件权限chmod"></a>10 文件权限chmod</h3><pre><code>1 rwx                 r-x       r-x
  属主(文件所有者)      属组权限    其他人权限
2 权限详解
    r：read写权限
    w: write写权限
    x:可执行
3 修改权限
    7=4(r)+2(w)+1(x)
    chmod 777 文件夹/文件</code></pre>
<h3 id="11-源码安装软件"><a href="#11-源码安装软件" class="headerlink" title="11 源码安装软件"></a>11 源码安装软件</h3><pre class=" language-python"><code class="language-python"><span class="token number">1</span> 会了yum安装，为什么还要会二进制安装（编译安装）
    <span class="token operator">-</span>官方不提供yum安装
    <span class="token operator">-</span>二进制安装是最新的
<span class="token number">2</span> 向服务器传递文件的几种方式 
    <span class="token operator">-</span>scp nginx<span class="token number">-1.18</span><span class="token punctuation">.</span><span class="token number">0.</span>tar<span class="token punctuation">.</span>gz root@<span class="token number">101.133</span><span class="token punctuation">.</span><span class="token number">225.166</span><span class="token punctuation">:</span><span class="token operator">/</span>home<span class="token operator">/</span>jack 
    <span class="token operator">-</span>sz，rz
    <span class="token operator">-</span>xftp软件来传

    <span class="token comment" spellcheck="true">#1.基础环境准备</span>
<span class="token punctuation">[</span>root@node1 <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># yum install -y gcc make wget </span>

<span class="token comment" spellcheck="true">#2.下载源码包</span>
<span class="token punctuation">[</span>root@node1 <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># wget http://nginx.org/download/nginx-1.15.12.tar.gz</span>

<span class="token comment" spellcheck="true">#3.解压源码包, 并进入相应目录</span>
<span class="token punctuation">[</span>root@node1 <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># tar xf nginx-1.15.12.tar.gz</span>
<span class="token punctuation">[</span>root@node1 <span class="token operator">~</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># cd nginx-1.15.12</span>

<span class="token comment" spellcheck="true">#4.配置相关的选项，并生成Makefile</span>
<span class="token punctuation">[</span>root@node1 nginx<span class="token number">-1.15</span><span class="token punctuation">.</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ./configure --help</span>
<span class="token punctuation">[</span>root@node1 nginx<span class="token number">-1.15</span><span class="token punctuation">.</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ./configure --prefix=/usr/local/nginx</span>
<span class="token punctuation">[</span>root@node1 nginx<span class="token number">-1.15</span><span class="token punctuation">.</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># echo $? # 检查上一个命令是否执行成功</span>

<span class="token comment" spellcheck="true">#5.将Makefile文件编译可执行二进制程序，此时,/usr/local/nginx可执行文件还不在，需要执行make install 才能copy过去</span>
<span class="token punctuation">[</span>root@node1 nginx<span class="token number">-1.15</span><span class="token punctuation">.</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># make</span>

<span class="token comment" spellcheck="true">#6.将二进制文件拷贝至对应的目录中</span>
<span class="token punctuation">[</span>root@node1 nginx<span class="token number">-1.15</span><span class="token punctuation">.</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># make install</span>

<span class="token comment" spellcheck="true">#7 建立软连接（以后方便升级）</span>
<span class="token punctuation">[</span>root@node1 nginx<span class="token number">-1.15</span><span class="token punctuation">.</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ln -s nginx-1.18.0 nginx</span>

<span class="token comment" spellcheck="true">#8 目录介绍</span>
conf<span class="token punctuation">:</span>配置文件
html：网站文件存放
logs：日志
sbin<span class="token punctuation">:</span>可执行文件

<span class="token comment" spellcheck="true"># 9 命令</span>
nginx  <span class="token comment" spellcheck="true"># 启动</span>
nginx <span class="token operator">-</span>s reload <span class="token comment" spellcheck="true"># 重新加载</span>
nginx <span class="token operator">-</span>s stop  <span class="token comment" spellcheck="true"># 重启</span>
nginx <span class="token operator">-</span>s stop <span class="token comment" spellcheck="true"># 停止</span></code></pre>
<h3 id="12-进程管理"><a href="#12-进程管理" class="headerlink" title="12 进程管理"></a>12 进程管理</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#1  ps -aux 用它，[系统进程]</span>
<span class="token comment" spellcheck="true">#2  ps -ef</span>
<span class="token comment" spellcheck="true">#3  ps -aux|grep id,进程名字，</span>
<span class="token comment" spellcheck="true"># 4 top实时看状态</span>
<span class="token comment" spellcheck="true"># 5 kill -l</span>
<span class="token comment" spellcheck="true"># 6 kill -9 进程id号 强行关闭</span>
<span class="token comment" spellcheck="true"># 7 pkill -9 nginx  关闭nginx所有进程</span>
<span class="token comment" spellcheck="true"># 8 killall nginx   关闭nginx所有进程</span>


<span class="token comment" spellcheck="true"># 通过来管理进程screen</span>
yum install screen <span class="token operator">-</span>y
创建一个窗口
screen <span class="token operator">-</span>S myjobs
执行耗时任务，进程
ctrl<span class="token operator">+</span>a<span class="token operator">+</span>d  退出当前bashshell但是耗时任务还在后台运行
screen <span class="token operator">-</span>r myjobs 调到前台执行
screen <span class="token operator">-</span>list  查看所有任务
</code></pre>
<h3 id="13-系统服务"><a href="#13-系统服务" class="headerlink" title="13 系统服务"></a>13 系统服务</h3><pre class=" language-python"><code class="language-python"><span class="token comment" spellcheck="true">#1  centos6 上启动服务service start network</span>
<span class="token comment" spellcheck="true">#2  centos7 启动服务：systemctl start network</span>

<span class="token comment" spellcheck="true"># 制作系统服务其实就是编写一堆配置，在配置文件中最起码要有这个程序的启动和关闭命令</span>
<span class="token comment" spellcheck="true"># 如果有必要也可以做成系统服务</span>
<span class="token comment" spellcheck="true">#3  cd /usr/lib/systemd/system/</span>

<span class="token comment" spellcheck="true">###制作系统服务</span>

<span class="token comment" spellcheck="true">#4 vim mynginx.service</span>
<span class="token punctuation">[</span>Unit<span class="token punctuation">]</span>
Description<span class="token operator">=</span>my nginx
After<span class="token operator">=</span>network<span class="token punctuation">.</span>target  <span class="token comment" spellcheck="true">#在哪个服务启动后启动</span>
<span class="token punctuation">[</span>Service<span class="token punctuation">]</span>
Type<span class="token operator">=</span>forking
ExecStart<span class="token operator">=</span><span class="token operator">/</span>usr<span class="token operator">/</span>local<span class="token operator">/</span>nginx<span class="token operator">/</span>sbin<span class="token operator">/</span>nginx
ExecStop<span class="token operator">=</span><span class="token operator">/</span>usr<span class="token operator">/</span>local<span class="token operator">/</span>nginx<span class="token operator">/</span>sbin<span class="token operator">/</span>nginx <span class="token operator">-</span>s stop
ExecRestart<span class="token operator">=</span><span class="token operator">/</span>usr<span class="token operator">/</span>local<span class="token operator">/</span>nginx<span class="token operator">/</span>sbin<span class="token operator">/</span>nginx <span class="token operator">-</span>s restart
ExecReload<span class="token operator">=</span><span class="token operator">/</span>usr<span class="token operator">/</span>local<span class="token operator">/</span>nginx<span class="token operator">/</span>sbin<span class="token operator">/</span>nginx <span class="token operator">-</span>s reload
<span class="token punctuation">[</span>Install<span class="token punctuation">]</span>
WantedBy<span class="token operator">=</span>multi<span class="token operator">-</span>user<span class="token punctuation">.</span>target

<span class="token comment" spellcheck="true"># 以后就支持使用 systemctl start mynginx.service</span>

<span class="token comment" spellcheck="true"># 查看服务状态：</span>
    systemctl status mynginx<span class="token punctuation">.</span>service
    <span class="token comment" spellcheck="true"># disabled表示没有开机自启动</span>
    Loaded<span class="token punctuation">:</span> loaded <span class="token punctuation">(</span><span class="token operator">/</span>usr<span class="token operator">/</span>lib<span class="token operator">/</span>systemd<span class="token operator">/</span>system<span class="token operator">/</span>mynginx<span class="token punctuation">.</span>service<span class="token punctuation">;</span> disabled<span class="token punctuation">;</span> vendor preset<span class="token punctuation">:</span> disabled<span class="token punctuation">)</span>
<span class="token comment" spellcheck="true"># 开机自启动</span>
    systemctl enable mynginx
<span class="token comment" spellcheck="true"># 取消开机自启动</span>
systemctl disable mynginx<span class="token punctuation">.</span>service</code></pre>
</div><div id="reward-container"><span class="hty-icon-button button-glow" id="reward-button" title="打赏" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === &quot;none&quot;) ? &quot;block&quot; : &quot;none&quot;;"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-hand-coin-line"></use></svg></span><div id="reward-comment">点我就给你看点有意思的</div><div id="qr" style="display:none;"><div style="display:inline-block"><a target="_blank" rel="noopener" href="https://gitee.com/huang_zhao/hz/raw/master/hz/alipay.png"><img loading="lazy" src="https://gitee.com/huang_zhao/hz/raw/master/hz/alipay.png" alt="支付宝" title="支付宝"></a><div><span style="color:#00A3EE"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-alipay-line"></use></svg></span></div></div><div style="display:inline-block"><a target="_blank" rel="noopener" href="https://gitee.com/huang_zhao/hz/raw/master/hz/qqpay.jpg"><img loading="lazy" src="https://gitee.com/huang_zhao/hz/raw/master/hz/qqpay.jpg" alt="QQ 支付" title="QQ 支付"></a><div><span style="color:#12B7F5"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-qq-line"></use></svg></span></div></div><div style="display:inline-block"><a target="_blank" rel="noopener" href="https://gitee.com/huang_zhao/hz/raw/master/hz/wxpay.jpg"><img loading="lazy" src="https://gitee.com/huang_zhao/hz/raw/master/hz/wxpay.jpg" alt="微信支付" title="微信支付"></a><div><span style="color:#2DC100"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-wechat-pay-line"></use></svg></span></div></div></div></div><ul class="post-copyright"><li class="post-copyright-author"><strong>本文作者：</strong>爱肖彤真是太好了</li><li class="post-copyright-link"><strong>本文链接：</strong><a href="http://huang_zhao.gitee.io/task/2021/03/15/%E5%85%B6%E4%BB%96/linux%E5%AD%A6%E4%B9%A0/" title="linux学习">http://huang_zhao.gitee.io/task/2021/03/15/%E5%85%B6%E4%BB%96/linux%E5%AD%A6%E4%B9%A0/</a></li><li class="post-copyright-license"><strong>版权声明：</strong>本博客所有文章除特别声明外，均默认采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank" rel="noopener" title="CC BY-NC-SA 4.0 "><svg class="icon"><use xlink:href="#icon-creative-commons-line"></use></svg><svg class="icon"><use xlink:href="#icon-creative-commons-by-line"></use></svg><svg class="icon"><use xlink:href="#icon-creative-commons-nc-line"></use></svg><svg class="icon"><use xlink:href="#icon-creative-commons-sa-line"></use></svg></a> 许可协议。</li></ul></section></article><div class="post-nav"><div class="post-nav-item"><a class="post-nav-prev" href="/task/2021/05/15/python/%E6%A1%86%E6%9E%B6/django%20%E7%9F%A5%E8%AF%86%E7%82%B9%E6%89%A9%E5%B1%95/" rel="prev" title="django知识点扩展"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-left-s-line"></use></svg><span class="post-nav-text">django知识点扩展</span></a></div><div class="post-nav-item"><a class="post-nav-next" href="/task/2020/09/19/%E5%89%8D%E7%AB%AF/Typescript%20%E6%8E%A5%E5%8F%A3/" rel="next" title="Typescript 接口"><span class="post-nav-text">Typescript 接口</span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-right-s-line"></use></svg></a></div></div></div></main><footer class="sidebar-translate" id="footer"><div class="copyright"><span>&copy; 2019 – 2022 </span><span class="with-love" id="animate"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-cloud-line"></use></svg></span><span class="author"> 爱肖彤真是太好了</span></div><div class="powered"><span>由 <a href="https://hexo.io" target="_blank" rel="noopener">Hexo</a> 驱动 v5.1.1</span><span class="footer-separator">|</span><span>主题 - <a rel="noopener" href="https://github.com/YunYouJun/hexo-theme-yun" target="_blank"><span>Yun</span></a> v0.9.7</span></div><div class="live_time"><span>本博客已萌萌哒地运行</span><span id="display_live_time"></span><span class="moe-text">(●'◡'●)</span><script>function blog_live_time() {
  window.setTimeout(blog_live_time, 1000);
  const start = new Date('2019-04-12T00:00:00');
  const now = new Date();
  const timeDiff = (now.getTime() - start.getTime());
  const msPerMinute = 60 * 1000;
  const msPerHour = 60 * msPerMinute;
  const msPerDay = 24 * msPerHour;
  const passDay = Math.floor(timeDiff / msPerDay);
  const passHour = Math.floor((timeDiff % msPerDay) / 60 / 60 / 1000);
  const passMinute = Math.floor((timeDiff % msPerHour) / 60 / 1000);
  const passSecond = Math.floor((timeDiff % msPerMinute) / 1000);
  display_live_time.innerHTML = " " + passDay + " 天 " + passHour + " 小时 " + passMinute + " 分 " + passSecond + " 秒";
}
blog_live_time();
</script></div><div id="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_site_uv" title="总访客量"><span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-user-line"></use></svg></span><span id="busuanzi_value_site_uv"></span></span><span class="footer-separator">|</span><span id="busuanzi_container_site_pv" title="总访问量"><span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-eye-line"></use></svg></span><span id="busuanzi_value_site_pv"></span></span></div></footer><a class="hty-icon-button" id="goUp" aria-label="back-to-top" href="#"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-up-s-line"></use></svg><svg class="progress-circle-container" viewBox="0 0 100 100"><circle class="progress-circle" id="progressCircle" cx="50" cy="50" r="48" fill="none" stroke="#0078E7" stroke-width="2" stroke-linecap="round"></circle></svg></a><a class="popup-trigger hty-icon-button icon-search" id="search" href="javascript:;" title="搜索"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-search-line"></use></svg></span></a><script>window.addEventListener("DOMContentLoaded", () => {
  // Handle and trigger popup window
  document.querySelector(".popup-trigger").addEventListener("click", () => {
    document.querySelector(".popup").classList.add("show");
    setTimeout(() => {
      document.querySelector(".search-input").focus();
    }, 100);
  });

  // Monitor main search box
  const onPopupClose = () => {
    document.querySelector(".popup").classList.remove("show");
  };

  document.querySelector(".popup-btn-close").addEventListener("click", () => {
    onPopupClose();
  });

  window.addEventListener("keyup", event => {
    if (event.key === "Escape") {
      onPopupClose();
    }
  });
});
</script><script src="/task/js/search/local-search.js" defer></script><div class="popup search-popup"><div class="search-header"><span class="popup-btn-close close-icon hty-icon-button"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-close-line"></use></svg></span></div><div class="search-input-container"><input class="search-input" id="local-search-input" type="text" placeholder="搜索..." value=""></div><div id="local-search-result"></div></div></div><script defer src="/task/js/utils.js"></script><script defer src="/task/js/hexo-theme-yun.js"></script></body></html>